package aitsm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Connect_class {
    XMLConfig cf = new XMLConfig();
//    protected Connection con = null;    
//    public Connect_class(){
//        try{                       
////            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
////            String str_con = "jdbc:sqlserver://pcpro; databasename = AITSM; username = sa; password = 123456";
////            this.con = DriverManager.getConnection(str_con);
////            if(con != null)
////                System.out.println("connect successfully");
////            else
////                System.out.println("connect failed");
//        }catch(Exception ex){
//            System.out.print(ex);
//        }
//    };    
//    public Connection getConnection(){
//        return this.con;
//    }
    public ResultSet getRecordSet(String query_SQL){
        ResultSet rs = null;
        try{            
            Statement sm = XMLConfig.con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = sm.executeQuery(query_SQL);
        }catch(Exception ex){
            System.out.print(ex);
        }
        return rs;
    }
    public void closeConnection(){
        try{
            XMLConfig.con.close();
        }catch(Exception ex){
            System.out.println(ex);
        }        
    }
//    public void JTableCheckBoxRecordSet(JTable jtable, ResultSet rs){
//        DefaultTableModel dtm = new DefaultTableModel();
//        int col_num = dtm.getColumnCount();
//        JCheckBoxRenderer jr = new JCheckBoxRenderer();
//        final JCheckBox choose = new JCheckBox();        
//        try{
//            int numCol = rs.getMetaData().getColumnCount();            
//            for(int i = 0; i < numCol; i++){
//                dtm.addColumn(rs.getMetaData().getColumnName(i + 1));
//            }
//            dtm.addColumn("Selection"); 
//            Vector v_temp;
//            if(rs != null){
//               while(rs.next()){
//                    v_temp = new Vector();
//                    for(int i = 1; i < numCol; i++){
//                        v_temp.add(rs.getString(rs.getMetaData().getColumnName(col_num - (col_num - i))));                      
//                    }                    
//                    dtm.addRow(v_temp);
//               }
//            }
//            jtable.setModel(dtm);
//            jtable.getColumn("Selection").setCellEditor(new DefaultCellEditor(choose));
//            jtable.getColumn("Selection").setCellRenderer(jr);              
//        }catch(Exception ex){
//            System.out.print(ex);
//        }
//    }
//    public void JCompoBoxRecordSet(JComboBox jb, ResultSet rs, int colNum){       
//        try{
//            if(rs != null){                
//                while(rs.next()){                    
//                   jb.addItem(rs.getString(colNum));                   
//                }                
//            }
//        }catch(Exception ex){
//            System.out.print(ex);
//        }     
//    }
}

